home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 15 / BBS in a box XV-2.iso / Files II / Music / J-L / Loop Sequencer 1.0.sit / Source / KeyUtils.c++ / KeyUtils.c++
Encoding:
C/C++ Source or Header  |  1994-09-19  |  1.1 KB  |  59 lines  |  [TEXT/MMCC]

  1. /*
  2.     KeyUtils.c++
  3.     Written by Hiep Dam.
  4.     Last Update: Sept. 1994
  5. */
  6. #include "KeyUtils.h"
  7.  
  8. Boolean IsKeyDown(unsigned short theKey);
  9. Boolean IsKeyDown(unsigned short theKey)
  10. // theKey =  any keyboard scan code, 0-127
  11. {
  12.     unsigned char km[16];
  13.  
  14.     GetKeys((long *) km);
  15.     return ((km[theKey>>3] >> (theKey & 7)) & 1);
  16. }
  17.  
  18. Boolean CmdKeyDown() {
  19.     return IsKeyDown(0x37);
  20. }
  21.  
  22. Boolean OptionKeyDown() {
  23.     return IsKeyDown(0x3A);
  24. }
  25.  
  26. Boolean ShiftKeyDown() {
  27.     return IsKeyDown(0x38);
  28. }
  29.  
  30. Boolean CapsKeyDown() {
  31.     return IsKeyDown(0x39);
  32. }
  33.  
  34. Boolean ControlKeyDown() {
  35.     return IsKeyDown(0x3B);
  36. }
  37.  
  38. // ---------------------------------------------------------------------------
  39.  
  40. Boolean StrNumberOnly(Str255 theStr, Boolean includePeriod, Boolean includeComma) {
  41.     Boolean numOnly = true;
  42.     
  43.     for (short i = 1; i <= theStr[0]; i++) {
  44.         if (theStr[i] >= '0' && theStr[i] <= '9') {
  45.         }
  46.         else if (includePeriod && theStr[i] == '.') {
  47.         }
  48.         else if (includeComma && theStr[i] == ',') {
  49.         }
  50.         else if (theStr[i] == '+' || theStr[i] == '-') {
  51.         }
  52.         else {
  53.             numOnly = false;
  54.             break;
  55.         }
  56.     }
  57.  
  58.     return(numOnly);
  59. } // END StrNumberOnly